#include <pthread.h>
#include "../include/ehome.h"
#include "mp3_player_hw.h"

pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t conti = PTHREAD_COND_INITIALIZER;
int music_stat=-1;
/* 　状态机 
 *　music_stat:-1(初始状态)　0(播放状态)　1(暂停状态)　
 *              2(下一首状态)　３(上一首状态)　　
 * */
void mp3(int cmd){
    pthread_t musicplay_pid;
    pthread_mutex_lock(&lock);
    switch(cmd){
        case MUSIC_PLAY:
            if(music_stat==-1){
                pr_debug("mp3_player.c\n");
                pthread_create(&musicplay_pid,0,music_play,0);
            }else if(music_stat==1){
                pthread_cond_signal(&conti);
            }
            music_stat=0;
            break;
        case MUSIC_PAUSE:
            music_stat=1;
            break;
        case MUSIC_NEXT:
            music_stat=2;
            break;
        case MUSIC_PREV:
            music_stat=3;
            break;
        default:
            printf("unknown music command!\n");
            break;
    }
    pthread_mutex_unlock(&lock);
}

